<template>
  <div class="result-info-wrap">
    <CommonCustomNavHead title="报告详情" theme="light"  :pageOffsetTop="pageOffsetTop" fixColor="#fff" navBgColor="#51D1E5" :isBack="true" />
    <div class="report-box">
      <div class="head-text">
        <div class="time">{{ reportDtail.assess_time }}</div>
        <div class="assessor">评估员：{{ acc_name }}</div>
      </div>
      <template v-for="(item, index) in questionResult">
        <div v-if="item.is_show && item.type !== 8" class="result-card" :key="index">
          <div class="bg-title">
            <div class="bg" :style="{background: titleIcon[item.type].totleColor}"></div>
            <div class="title-font">
              <img :src="titleIcon[item.type].icon" alt="">
              <div class="font">{{tem.type == 7 ? '日常生活活动能力评估' : item.title }}</div> 
            </div>
          </div>

          <div v-if="item.type == 7" class="both-title">{{item.title}}</div>
          <div class="result-score-box">
            <div v-if="item.type == 1" class="score"></div>
            <div v-else class="score">{{item.score}}分</div>
            <div class="font">{{item.result}}</div>
            <img class="icon" src="https://www.thuguardian.com/files/small_program/icon-warning.png" alt="" @click="handleTips(item)">
          </div>
          <div class="progress-box">
            <div class="bar-box">
              <div
                v-for="(val, index) in item.bar"
                :key="index"
                :style="{
                  width: (100 / item.bar) + '%',
                  background: progressColor[index]
                }"
                :class="'bar' + index"
                class="bar"></div>
            </div>
            <div
              class="bar-font"
              :style="{
                marginLeft: ((100 / item.bar) * (item.bar_level -1)) + '%',
                width: (100 / item.bar) + '%',
                color: progressColor[item.bar_level -1]
              }">
              {{ item.bar_font_arr[item.bar_level -1] }}
              <img class="bar-icon" :src="progressArrow[item.bar_level -1]" alt="">
            </div>
          </div>

          <template v-if="item.type == 7">
            <div class="both-title">{{questionResult[questionResult.length - 1].title}}</div>
            <div class="result-score-box">
              <div class="score">{{questionResult[questionResult.length - 1].score}}分</div>
              <div class="font">{{questionResult[questionResult.length - 1].result}}</div>
              <img class="icon" src="https://www.thuguardian.com/files/small_program/icon-warning.png" alt="" @click="handleTips(questionResult[questionResult.length - 1])">
            </div>
            <div class="progress-box">
              <div class="bar-box">
                <div
                  v-for="(val, index) in questionResult[questionResult.length - 1].bar"
                  :key="index"
                  :style="{
                    width: (100 / questionResult[questionResult.length - 1].bar) + '%',
                    background: progressColor[index]
                  }"
                  :class="'bar' + index"
                  class="bar"></div>
              </div>
              <div
                class="bar-font"
                :style="{
                  marginLeft: ((100 / questionResult[questionResult.length - 1].bar) * (questionResult[questionResult.length - 1].bar_level -1)) + '%',
                  width: (100 / questionResult[questionResult.length - 1].bar) + '%',
                  color: progressColor[questionResult[questionResult.length - 1].bar_level -1]
                }">
                  {{ questionResult[questionResult.length - 1].bar_font_arr[questionResult[questionResult.length - 1].bar_level -1] }}
                <img class="bar-icon" :src="progressArrow[questionResult[questionResult.length - 1].bar_level -1]" alt="">
              </div>
            </div>
          </template>
        </div>
      </template>

      
      <!-- 预警 -->
      <!-- <div class="result-card"> -->
      <div class="result-card" v-if="questionWarning && questionWarning.filter(v => v.isHas) && questionWarning.filter(v => v.isHas).length > 0">
        <div class="bg-title">
          <div class="bg"></div>
          <div class="title-font">
            <img src="https://www.thuguardian.com/files/small_program/ques-8.png" alt="">
            <div class="font">预警</div>
          </div>
        </div>
        
        <div v-for="(item, index) in questionWarning" :key="index" class="early-item">
          <div v-if="item.isHas">
          <!-- <div> -->
            <div class="label">{{ item.label }}</div>
            <div class="earli-data">
              <div class="current">
                <!-- <div v-if="item.id == 1 || item.id == 2">{{ item.score }}分</div>
                <div v-if="item.id == 3"></div>
                <div v-if="item.id == 4"></div> -->
                <div></div>
                
                <div v-if="item.isHas">{{ item.result }}</div>
                <div v-else>无</div>
              </div>
              <!-- <div v-else class="current">无</div> -->
              

              <div v-if="item.pre_trend" class="contrast">
                <div v-if="item.label != '跌倒' && item.label != '疼痛'" class="contrast-item">
                  <div v-if="item.pre_trend.score_change == 1" class="font">与上次相比高{{ item.pre_trend.score }}分</div>
                  <div v-if="item.pre_trend.score_change == 2" class="font">与上次相比低{{ item.pre_trend.score }}分</div>
                  <div v-if="item.pre_trend.score_change == 0" class="font">与上次持平</div>
                  <img v-if="item.pre_trend.score_change && item.pre_trend.score_change == 1" src="https://www.thuguardian.com/files/small_program/Frame (9).png" alt="">
                  <img v-if="item.pre_trend.score_change && item.pre_trend.score_change == 2" src="https://www.thuguardian.com/files/small_program/Frame (10).png" alt="">
                  <div v-if="item.pre_trend && item.pre_trend.score_change == 0" class="img-font">--</div>
                </div>
                <div v-else class="contrast-item">
                  <div class="font">上一次等级：{{ item.pre_trend.pre_result || '无' }}</div>
                </div>
                <div class="contrast-item">
                  <div class="font">风险等级{{ item.pre_trend.level_change == 1 ? '升高' : (item.pre_trend.level_change == 2 ? '降低' : '不变')  }}</div>
                  <img v-if="item.pre_trend.level_change && item.pre_trend.level_change == 1" src="https://www.thuguardian.com/files/small_program/Frame (9).png" alt="">
                  <img v-if="item.pre_trend.level_change && item.pre_trend.level_change == 2" src="https://www.thuguardian.com/files/small_program/Frame (10).png" alt="">
                  <div v-if="item.pre_trend && item.pre_trend.level_change == 0" class="img-font">--</div>
                </div>
              </div>
            </div>
          </div>
        </div>

      </div>

      <!-- 评价 -->
      <div class="pingjia-card">
        <div class="label">评估员评价</div>
        <img
          v-if="!editStatus && oldEvaluateResult.evaluate"
          @click="handleEditStatus"
          class="pingjia-icon"
          src="https://www.thuguardian.com/files/small_program/icon-edit.png" alt="">
        <div :class="editStatus ? 'pj-imgs' : 'pj-imgs view'">
          <div
            class="items"
            v-for="(item, index) in evaluate"
            :key="index"
            @click="handleEvaluate(item)">
            <template v-if="evaluateResult.evaluate == item.level">
              <img  :src="item.images_active" alt="">
              <div class="font">{{ item.label }}</div>
            </template>
            <template v-else-if="editStatus">
              <img  :src="item.images" alt="">
              <div class="font">{{ item.label }}</div>
            </template>
          </div>
        </div>
        
        <div class="star-box service-star">
          <div class="label">服务态度</div>
          <img
            v-for="(item, index) in 5"
            :key="index"
            @click="handleService(index)"
            class="star-img"
            :src="`https://www.thuguardian.com/files/small_program/star${evaluateResult.service && (index < evaluateResult.service) ? '-active' : ''}.png`" alt="">
          
          <div class="evaluate-score" v-if="evaluateResult.service">{{ evaluateResult.service }}分</div>
        </div>
        
        <div class="star-box major-star">
          <div class="label">专业水平</div>
          <img
            v-for="(item, index) in 5"
            :key="index"
            @click="handleMajor(index)"
            class="star-img"
            :src="`https://www.thuguardian.com/files/small_program/star${evaluateResult.major && (index < evaluateResult.major) ? '-active' : ''}.png`" alt="">
            <div class="evaluate-score" v-if="evaluateResult.major">{{ evaluateResult.major }}分</div>
        </div>

        <div v-if="editStatus || (!editStatus && evaluateResult.description)" class="font-content">
          <van-field
            v-if="editStatus"
            class="con"
            :value="evaluateResult.description"
            type="textarea"
            placeholder="请留下的您的评价，让我们变得更好～"
            :border="false"
            maxlength="88"
            :show-word-limit="true"
            :autosize="{
              maxHeight: 116,
              minHeight: 116
            }"
            clearable
            @change="handleContent"
          />
          <div v-else>{{ evaluateResult.description }}</div>
        </div>

        <button
          v-if="editStatus"
          :disabled="!(evaluateResult.evaluate && evaluateResult.service && evaluateResult.major)"
          :class="!(evaluateResult.evaluate && evaluateResult.service && evaluateResult.major) ? 'disabled pj-btn' : 'pj-btn'"
          @click="confirmEvaluate">评价</button>
      </div>

    </div>

    <van-dialog
      use-slot
      :title="tipsTitle"
      :show="tipsShow"
      confirm-button-text="我知道了"
      confirm-button-color="#00AFCB"
      @close="handleClose"
      @confirm="handleClose"
    >
      <!-- <div class="tip-content">{{ tips }}</div> -->
      <div class="tip-content">
        <div v-for="(item, index) in tips" :key="index">{{ item }}</div>
      </div>
    </van-dialog>
  </div>
</template>

<script>
  import Dialog from '@/wxcomponents/vant/dialog/dialog';
  import CommonCustomNavHead from '@/components/CommonCustomNavHead/index.vue';
  import { questionnaireInfo, questionnaireGetAppInfo , assessmentGet, assessmentAdd, assessmentUpdate } from '@/api/report/index.js'
  export default {
    components: {
      CommonCustomNavHead
    },
    data() {
      return {
        token: '',
        id: 0,
        acc_name: '',
        pageOffsetTop: 0,
        reportDtail: {},
        questionResult: [],
        progressColor: ['#59D488', '#D9D44B', '#FF6600', '#CB392B', '#9A281E'],
        progressFont: ['正常', '轻度', '中度', '严重', '完全'],
        progressArrow: [
          'https://www.thuguardian.com/files/small_program/level-arrow-1.png',
          'https://www.thuguardian.com/files/small_program/level-arrow-2.png',
          'https://www.thuguardian.com/files/small_program/level-arrow-3.png',
          'https://www.thuguardian.com/files/small_program/level-arrow-4.png',
          'https://www.thuguardian.com/files/small_program/level-arrow-5.png'
        ],
        titleIcon: {
          0: {
            icon: 'https://www.thuguardian.com/files/small_program/ques-1.png',
            totleColor: '#C4FFC1'
          },
          1: {
            icon: 'https://www.thuguardian.com/files/small_program/ques-1.png',
            totleColor: '#C4FFC1'
          },
          2: {
            icon: 'https://www.thuguardian.com/files/small_program/ques-2.png',
            totleColor: '#ACEFFA'
          },
          3: {
            icon: 'https://www.thuguardian.com/files/small_program/ques-3.png',
            totleColor: '#C4FFC1'
          },
          4: {
            icon: 'https://www.thuguardian.com/files/small_program/ques-4.png',
            totleColor: '#ACEFFA'
          },
          5: {
            icon: 'https://www.thuguardian.com/files/small_program/ques-5.png',
            totleColor: '#C4FFC1'
          },
          6: {
            icon: 'https://www.thuguardian.com/files/small_program/ques-6.png',
            totleColor: '#ACEFFA'
          },
          7: {
            icon: 'https://www.thuguardian.com/files/small_program/ques-7.png',
            totleColor: '#C4FFC1'
          },
          8: {
            icon: 'https://www.thuguardian.com/files/small_program/ques-7.png',
            totleColor: '#ACEFFA'
          }
        },
        tipsShow: false,
        tipsTitle: '',
        tips: [],
        // 预警
        questionWarning: [],
        evaluate: [
          {
            level: 1,
            images: 'https://www.thuguardian.com/files/small_program/rate-1.png',
            images_active: 'https://www.thuguardian.com/files/small_program/rate-active-1.png',
            label: '非常差'
          },
          {
            level: 2,
            images: 'https://www.thuguardian.com/files/small_program/rate-2.png',
            images_active: 'https://www.thuguardian.com/files/small_program/rate-active-2.png',
            label: '差'
          },
          {
            level: 3,
            images: 'https://www.thuguardian.com/files/small_program/rate-3.png',
            images_active: 'https://www.thuguardian.com/files/small_program/rate-active-3.png',
            label: '一般'
          },
          {
            level: 4,
            images: 'https://www.thuguardian.com/files/small_program/rate-4.png',
            images_active: 'https://www.thuguardian.com/files/small_program/rate-active-4.png',
            label: '满意'
          },
          {
            level: 5,
            images: 'https://www.thuguardian.com/files/small_program/rate-5.png',
            images_active: 'https://www.thuguardian.com/files/small_program/rate-active-5.png',
            label: '超赞'
          }
        ],
        // 进入编辑 或 评价状态
        editStatus: true,
        oldEvaluateResult: {
          evaluate: 5,
          service: 5,
          major: 5,
          description: '123'
        },
        evaluateResult: {
          quest_id: 0,
          evaluate: 5,
          service: 5,
          major: 5,
          description: '123'
        }
      }
    },
    onLoad(options) {
      this.id = options.id
      this.acc_name = options.name || '--'
      this.evaluateResult.quest_id = options.id
      this.getInfo()
      this.getAppInfo()
      this.assessmentInfo()
    },
    onShow() {
      this.token = wx.getStorageSync('token');
    },
    onPageScroll ({scrollTop}) {
      this.pageOffsetTop = scrollTop
    },
    methods: {
      // 获取本次报告信息
      async getInfo () {
        const res = await questionnaireInfo({
          id: this.id
        })
        if (res.code == 200) {
          this.reportDtail = res.data
          this.questionResult = this.reportDtail.questionnaire.filter(item => item.type < 9).map(item => {
            if (item.type == 0) {
              item.bar = 3
              item.bar_level = 3
              item.bar_font_arr = ['正常', '中度', '重度']
              if (item.score > 12) {
                item.bar_level = 1
              } else if (item.score > 7) {
                item.bar_level = 2
              }
            } else if (item.type == 1) {
              item.bar = 4
              item.bar_level = 1
              item.bar_font_arr = ['正常', '轻度', '中度', '严重']
              if (item.result == '重度认知障碍') {
                item.bar_level = 4
              } else if (item.result == '中度认知障碍') {
                item.bar_level = 3
              } else if (item.result == '轻度认知障碍') {
                item.bar_level = 2
              }
            } else if (item.type == 2) {
              item.bar = 4
              item.bar_level = 1
              item.bar_font_arr = ['正常', '轻度', '中度', '严重']
              if (item.score < 5) {
                item.bar_level = 4
              } else if (item.score < 9) {
                item.bar_level = 3
              } else if (item.score < 13) {
                item.bar_level = 2
              }
            } else if (item.type == 3) {
              item.bar = 3
              item.bar_level = 1
              item.bar_font_arr = ['正常', '存在风险', '营养不良']
              if (item.score > 3) {
                item.bar_level = 3
              } else if (item.score >1) {
                item.bar_level = 2
              }
            } else if (item.type == 4) {
              item.bar = 4
              item.bar_level = 1
              item.bar_font_arr = ['正常', '轻度', '中度', '严重']
              if (item.score > 8) {
                item.bar_level = 4
              } else if (item.score > 5) {
                item.bar_level = 3
              } else if (item.score > 2) {
                item.bar_level = 2
              }
              // 特别说明： 即使总分较低，如果出现以下情况，也应提高一个等级评估：
              // 1. 任一项得到最高分（视/听力2分，表达/理解3分）
              // 2. 说话清晰度得2分（无法讲话）
              // 3. 自我表达和理解能力同时≥2分
              if (item.bar_level != 4) {
                const shili  = item?.question?.find(v => v.title.includes('视力评估'))
                const tingli  = item?.question?.find(v => v.title.includes('听力评估'))
                const shuohua  = item?.question?.find(v => v.title.includes('说话清晰度'))
                const biaoda  = item?.question?.find(v => v.title.includes('自我表达能力'))
                const lijie  = item?.question?.find(v => v.title.includes('理解他人能力'))
                const if1 = shili?.select.find(v => v.is_selected)?.title.includes('严重困难')
                  || tingli?.select.find(v => v.is_selected)?.title.includes('严重困难')
                  || biaoda?.select.find(v => v.is_selected)?.title.includes('很少或无法')
                  || lijie?.select.find(v => v.is_selected)?.title.includes('很少或无法')
                const if2 = shuohua?.select.find(v => v.is_selected)?.title.includes('无法讲话')
                const if3 = (biaoda?.select.find(v => v.is_selected)?.title.includes('很少或无法') || biaoda?.select.find(v => v.is_selected)?.title.includes('有时')) 
                  && (lijie?.select.find(v => v.is_selected)?.title.includes('很少或无法') || biaoda?.select.find(v => v.is_selected)?.title.includes('有时'))

                if (if1 || if2 || if3) {
                  item.bar_level++
                  const description = [
                    '感官与沟通能力正常',
                    '感官与沟通能力轻度受损',
                    '感官与沟通能力中度受损',
                    '感官与沟通能力重度受损'
                  ]
                  item.result = description[item.bar_level-1]
                }
              }
            } else if (item.type == 5) {
              item.bar = 2
              item.bar_level = 1
              item.bar_font_arr = ['倾向较低', '可能抑郁']
              if (item.score < 3) {
                item.bar_level = 1
              } else {
                item.bar_level = 2
              }
            } else if (item.type == 6) {
              item.bar = 4
              item.bar_level = 1
              item.bar_font_arr = ['正常', '轻度', '重度', '极严重']
              if (item.score > 6) {
                item.bar_level = 4
              } else if (item.score > 3) {
                item.bar_level = 3
              } else if (item.score > 0) {
                item.bar_level = 2
              }
            } else if (item.type == 7) {
              item.bar = 5
              item.bar_level = 1
              item.bar_font_arr = ['独立', '轻度依赖', '中度依赖', '严重依赖', '完全依赖']
              if (item.score == 100) {
                item.bar_level = 1
              } else if (item.score > 90) {
                item.bar_level = 2
              } else if (item.score > 60) {
                item.bar_level = 3
              } else if (item.score > 20) {
                item.bar_level = 4
              } else {
                item.bar_level = 5
              }
            } else if (item.type == 8) {
              item.bar = 3
              item.bar_level = 1
              item.bar_font_arr = ['轻度或独立', '中度', '严重']
              if (item.score > 5) {
                item.bar_level = 1
              } else if (item.score > 2) {
                item.bar_level = 2
              } else {
                item.bar_level = 3
              }
            }
            return item
          })
          
          // 预警数据处理在对比的报告接口里处理 getAppInfo
        }
      },
      // 获取最近两次的报告
      async getAppInfo () {
        const res = await questionnaireGetAppInfo({
          id: this.id
        })
        if (res.code == 200) {
          // 本次预警值处理  start
          const currentRe = res.data.quest
          const questionList = currentRe.questionnaire
          // 预警数据处理
          // 营养
          const yingYangResult = {
            id: 1,
            label: '营养',
            isHas: questionList.find(v => v.type == 3).score > 3,
            score: questionList.find(v => v.type == 3).score,
            result: questionList.find(v => v.type == 3).score > 3 ? '营养不良高风险' : '',
            pre_trend: false
          }
          // 抑郁
          const yiYuResult = {
            id: 2,
            label: '抑郁',
            isHas: questionList.find(v => v.type == 5).score > 2,
            score: questionList.find(v => v.type == 5).score,
            result: questionList.find(v => v.type == 5).score > 2 ? '存在抑郁风险' : '',
            pre_trend: false
          }
          console.log(999 )
          // 跌倒
          const dieDaoResult = this.dieDaData(questionList)
          console.log('909090909', dieDaoResult)
          // questionWarning.push(dieDaoResult)
          // 疼痛
          const tengTongResult = this.tengTong(questionList)
          // questionWarning.push(tengTongResult)
          // 本次预警值处理  end

          const isPre = res.data?.pre_quest?.id || false
          if (isPre) {
            // 上次预警的数据处理 start
            const preRe = res.data.pre_quest
            const perQuestionList = preRe.questionnaire
            // 营养
            const yingyangScore = perQuestionList.find(v => v.type == 3).score
            const yinyangResultFont = perQuestionList.find(v => v.type == 3).result
            const yingyangScoreMath = yingYangResult.score - yingyangScore
            yingYangResult.pre_trend = {
              score: Math.abs(yingyangScoreMath),
              score_change: yingyangScoreMath == 0 ? 0 : (yingyangScoreMath > 0 ? 1 : 2),
              level_change: (yingYangResult.result === yinyangResultFont || yingyangScoreMath == 0) ? 0 : (yingyangScoreMath > 0 ? 1 : 2),
            }
            // 抑郁
            const yiyuScore = perQuestionList.find(v => v.type == 3).score
            const yiyuResultFont = perQuestionList.find(v => v.type == 5).result
            const yiyuScoreMath =  yiYuResult.score - yiyuScore
            yiYuResult.pre_trend = {
              score: Math.abs(yiyuScoreMath),
              score_change: yiyuScoreMath == 0 ? 0 : (yiyuScoreMath > 0 ? 1 : 2),
              level_change: (yiYuResult.result === yiyuResultFont || yiyuScoreMath == 0) ? 0 : (yiyuScoreMath > 0 ? 1 : 2),
            }
            // 跌倒
            const preDieDaoResult = this.dieDaData(perQuestionList)
            const diedaoResultFont = preDieDaoResult.result
            dieDaoResult.pre_trend = {
              score: 0,
              pre_result: dieDaoResult.result,
              level_change: (dieDaoResult.result === diedaoResultFont) ? 0 : (diedaoResultFont.includes('高') ? 1 : 2),
            }
            // 疼痛
            const preTengTongResult = this.tengTong(perQuestionList)
            const tengtongScore = preTengTongResult.score
            const tengtongResultFont = preTengTongResult.result
            const tengtongScoreMath = tengTongResult.score - tengtongScore
            tengTongResult.pre_trend = {
              score: Math.abs(tengtongScoreMath),
              score_change: tengtongScoreMath == 0 ? 0 : (tengtongScoreMath > 0 ? 1 : 2),
              level_change: (tengTongResult.result === tengtongResultFont || tengtongScoreMath == 0) ? 0 : (tengtongScoreMath > 0 ? 1 : 2),
            }
            // 上次预警的数据处理 end
          }
          this.questionWarning = [yingYangResult, yiYuResult, dieDaoResult, tengTongResult]
        }
      },
      // 跌倒数据处理
      dieDaData (questionList) {
        const dieDaoList = questionList?.filter(v => v.title.includes('跌倒相关'))[0]
        const dieDao0 = dieDaoList?.question?.filter(v => v.title.includes('是否发生过跌倒'))[0]
        const dieDao1 = dieDaoList?.question?.filter(v => v.title.includes('跌倒高风险'))[0]
        const dieDao2 = dieDaoList?.question?.filter(v => v.title.includes('防跌倒措施'))[0]
        const dieDaoResult = {
          id: 3,
          label: '跌倒',
          isHas: false,
          score: '',
          result: '',
          pre_trend: false
        }
        if(!(dieDao0?.select?.find(v => v.is_selected).title == '否')) {
          if (Number(dieDao0?.select?.find(v => v.is_selected).value) >= 2 || (Number(dieDao0?.select?.find(v => v.is_selected).value) == 1 && dieDao1?.select?.find(v => v.is_selected)?.title == '是' && dieDao2?.select?.find(v => v.is_selected)?.title == '否') ) {
            // 过去3个月内跌倒2次及以上，或  过去3个月内跌倒1次且有高风险因素（走路不稳等）且未采取防跌倒措施
            dieDaoResult.result = '高风险'
            dieDaoResult.isHas = true
          } else if (Number(dieDao0?.select?.find(v => v.is_selected).value) == 1 || (dieDao1?.select?.find(v => v.is_selected)?.title == '是' && dieDao2?.select?.find(v => v.is_selected)?.title == '否')) {
            // 过去3个月内跌倒1次，或 有高风险因素且未采取防跌倒措施
            dieDaoResult.result = '中度风险'
            dieDaoResult.isHas = true
          }
        }
        return dieDaoResult
      },
      // 疼痛数据处理
      tengTong (questionList) {
        const tengTongList = questionList?.filter(v => v.title.includes('疼痛相关'))[0]
        const tengTong0 = tengTongList?.question?.filter(v => v.title.includes('是否存在'))[0]
        const tengTong1 = tengTongList?.question?.filter(v => v.title.includes('疼痛强度'))[0]
        const tengTong2 = tengTongList?.question?.filter(v => v.title.includes('疼痛管理'))[0]
        const tengTong3 = tengTongList?.question?.filter(v => v.title.includes('疼痛部位'))[0]
        const tengTongResult = {
          id: 4,
          label: '疼痛',
          isHas: false,
          score: '',
          result: '',
          pre_trend: false
        }
        if (!(tengTong0?.select?.find(v => v.is_selected).title == '否')) {
          if (Number(tengTong1?.select[0].value) >= 7 || (Number(tengTong1?.select[0].value) >= 5 && tengTong2?.select?.find(v => v.is_selected).title == '否')) {
            // 疼痛强度≥7分，或 疼痛强度≥5分且未进行任何疼痛管理
            tengTongResult.score = 7
            // tengTongResult.score = Number(tengTong1?.select[0].value)
            tengTongResult.result = '红色预警 (需立即关注)'
            tengTongResult.isHas = true
          } else if (Number(tengTong1?.select[0].value) >= 4 || (Number(tengTong1?.select[0].value) >= 2 && tengTong2?.select?.find(v => v.is_selected).title == '否') || (tengTong3?.select.filter(v => v.is_selected) >= 3)) {
            // 疼痛强度4-6分，或 疼痛强度2-3分但未进行疼痛管理，或 存在多处（≥3处）疼痛
            tengTongResult.score = 4
            // tengTongResult.score = Number(tengTong1?.select[0].value)
            tengTongResult.result = '黄色预警 (需要关注)'
            tengTongResult.isHas = true
          }
        }
        return tengTongResult
      },
      // 每个等级的解释
      handleTips (item) {
        this.tipsShow = true
        this.tipsTitle = item.title
        this.tips = item.description.split('；')
      },
      handleClose () {
        this.tipsShow = false
        this.tipsTitle = ''
        this.tips = []
      },
      // 评价
      handleEvaluate (item) {
        if (!this.editStatus) {
          return false
        }
        this.evaluateResult.evaluate = item.level
      },
      handleService (value) {
        if (!this.editStatus) {
          return false
        }
        this.evaluateResult.service = value +1
      },
      handleMajor (value) {
        if (!this.editStatus) {
          return false
        }
        this.evaluateResult.major = value +1
      },
      handleContent (e) {
        if (!this.editStatus) {
          return false
        }
        console.log(e, 'eeee')
        this.evaluateResult.description = e.detail
      },
      handleEditStatus () {
        this.editStatus = true
      },
      // 获取评价
      async assessmentInfo () {
        const res = await assessmentGet({
          id: this.id
        })
        if (res.code == 200) {
          // 如果有  this.editStatus = false
          // 同时给oldEvaluateResult 和 EvaluateResult 赋值
          if (res.data.created_at) {
            this.editStatus = false
            const result = {
              id: res.data.id,
              evaluate: +res.data.evaluate,
              service: +res.data.service,
              major: +res.data.major,
              description: res.data.description
            }
            this.oldEvaluateResult = result
            this.evaluateResult =  result
          } else {
            this.editStatus = true
            this.oldEvaluateResult = {
              evaluate: 0,
              service: 0,
              major: 0,
              description: ''
            }
            this.evaluateResult = {
              id: this.id,
              evaluate: 0,
              service: 0,
              major: 0,
              description: ''
            }
          }
        }
      },
      // 提交评价
      async confirmEvaluate () {
        if (this.oldEvaluateResult.id) {
          // 编辑
          console.log(888)
          const res = await assessmentUpdate(this.evaluateResult)
          if (res.code == 200) {
            uni.showToast({ title: '评价成功', icon: 'success' })
            this.assessmentInfo()
          }
        } else {
          console.log(999)
          const res = await assessmentAdd(this.evaluateResult)
          if (res.code == 200) {
            uni.showToast({ title: '评价成功', icon: 'success' })
            this.editStatus = false
            this.assessmentInfo()
          }
        }
        
      }
    }
  }
</script>

<style lang="less" scoped>
.result-info-wrap {
  padding-top: 80px;
  min-height: 100vh;
  width: 100%;
  box-sizing: border-box;
  background: url('https://www.thuguardian.com/files/small_program/bg01.png') no-repeat;
  background-size: 100% auto;
}

.report-box {
  padding: 20px 16px;
  box-sizing: border-box;
}
.head-text {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  height: 32px;
  font-size: 20px;
  font-weight: 500;
  color: rgba(0, 0, 0, .65);
}

.result-card {
  margin-top: 16px;
  padding: 14px 12px 14px 16px;
  background: #fff;
  border-radius: 12px;
  box-sizing: border-box;

  .bg-title {
    margin-bottom: 24px;
    width: 100%;
    height: 23px;
    position: relative;
    .bg {
      position: absolute;
      bottom: 0;
      left: 0;
      width: 100%;
      height: 10px;
      background: #FFC7C2;
      border-radius: 10px 10px 0 0;
      z-index: 10;
    }

    .title-font {
      position: absolute;
      top: 0;
      left: 0;
      display: flex;
      align-items: center;
      width: 100%;
      height: 23px;
      z-index: 11;

      img {
        display: block;
        margin-right: 8px;
        width: 23px;
        height: 23px;
      }

      .font {
        font-size: 20px;
        font-weight: 500;
        color: rgba(0, 0, 0, .85);
      }
    }
  }

  .both-title {
    margin-bottom: 12px;
    color: rgba(0, 0, 0, .65);
    font-size: 16px;
  }

  .result-score-box {
    padding: 10px 16px;
    display: flex;
    align-items: center;
    border-radius: 8px;
    background: #E5FAF7;
    font-size: 20px;
    line-height: 28px;
    color: rgba(0, 0, 0, .65);
    .font {
      margin-left: 28px;
      width: 180px;
    }
    .icon {
      margin-left: auto;
      display: block;
      width: 28px;
      height: 28px;
    }
  }

  .progress-box {
    padding-top: 28px;

    .bar-box {
      display: flex;
      align-items: center;
      width: 100%;
      height: 12px;
      box-sizing: border-box;
      border: 1px solid #fff;
    }
    .bar {
      height: 12px;
      border-left: 1px solid #fff;
      box-sizing: border-box;
      &:first-child {
        border-left: 0;
      }
    }

    .bar-font {
      margin-top: 8px;
      font-size: 18px;
      font-weight: 500;
      line-height: 25px;
      text-align: center;
      white-space: nowrap;
      position: relative;

      .bar-icon {
        position: absolute;
        left: 50%;
        top: -32px;
        margin-left: -12px;
        display: block;
        width: 24px;
        height: 24px;
      }
    }
  }

  .early-item {
    margin-top: 20px;
    width: 100%;
    .label {
      font-size: 20px;
      font-weight: 500;
      line-height: 1;
      color: rgba(0, 0, 0, .85);
    }

    .earli-data {
      margin-top: 16px;
      padding: 8px 8px 20px;
      border-radius: 4px;
      background: #E5FAF7;

      .current {
        display: flex;
        align-items: center;
        justify-content: space-between;
        font-size: 20px;
        color: #BD3D31;
      }

      .contrast {
        margin-top: 16px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 18px 8px;
        font-size: 14px;
        line-height: 20px;
        color: rgba(0, 0, 0, .65);
        border-radius: 8px;
        background: #fff;

        .contrast-item {
          display: flex;
          align-items: center;
          .font {
            margin-right: 8px;
          }
          img {
            display: block;
            width: 20px;
            height: 20px;
          }
          .img-font {
            color: #00AFCB;
            font-weight: 700;
          }
        }
      }
    }
    
  }
}

.pingjia-card {
  margin-top: 16px;
  padding: 16px 14px;
  background: #fff;
  border-radius: 12px;
  box-sizing: border-box;
  position: relative;
  .pingjia-icon {
    position: absolute;
    top: 16px;
    right: 15px;
    display: block;
    width: 24px;
    height: 24px;
  }
  .label {
    color: rgba(0, 0, 0, 0.85);
    font-family: "PingFang SC";
    font-size: 20px;
    font-style: normal;
    font-weight: 500;
    line-height: 23px;
  }

  .pj-imgs {
    margin-top: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    &.view {
      justify-content: center;
    }
    .items {
      img {
        margin: 0 auto;
        display: block;
        width: 45px;
        height: 45px;
      }
      .font {
        text-align: center;
        color: rgba(0, 0, 0, 0.45);
        font-family: "PingFang SC";
        font-size: 14x;
        font-style: normal;
        font-weight: 400;
        line-height: normal;
      }
    }
  }

  .star-box {
    margin-top: 16px;
    display: flex;
    align-items: center;
    padding: 12px;
    background: #E5FAF7;
    &.major-star {
      margin-top: 8px;
    }
    .label {
      margin-right: 10px;
      color: rgba(0, 0, 0, 0.65);
      font-family: "PingFang SC";
      font-size: 14px;
      font-style: normal;
      font-weight: 400;
      line-height: normal;
    }

    .star-img {
      display: block;
      margin-right: 8px;
      width: 28px;
      height: 28px;
    }

    .evaluate-score {
      margin-left: auto;
    }
  }

  .font-content {
    margin-top: 8px;
    padding: 12px;
    // height: 140px;
    background: #E5FAF7;
    box-sizing: border-box;

    .con {
      display: block;
      width: 100%;
      height: 100%;
    }
    /deep/ .van-cell {
      padding: 0;
      background: transparent;

      .van-field__control  {
        font-size: 16px;
        color: rgba(0, 0, 0, .65);
      }
    }
  }

  .pj-btn {
    margin-top: 16px;
    height: 48px;
    border-radius: 48px;
    color: #fff;
    background: linear-gradient(93deg, #00AFCB 19.12%, #1097B4 62.08%);
    &.disabled {
      opacity: .5;
    }
  }
}


.tip-content {
  padding: 10px 20px;
  font-size: 18px;
  color: rgba(0, 0, 0, .85);
  white-space: pre-line;
}
</style>